/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-10-21 23:41:10
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-01-14 13:47:41
 */

import { useDataStore } from "@/store";

const getUserName = (id: string) => {
  const { userItems } = useDataStore();
  let item = userItems.find((x) => x.id == id);
  return item?.name || "";
};
const getUserNames = (ids: Array<string>) => {
  const { userItems } = useDataStore();
  let items = userItems
    .filter((x) => ids.findIndex((x1) => x1 == x.id) !== -1)
    .map((x) => x.name);
  return items.join(",");
};

const getOrganizeName = (idOrCode: string) => {
  const { organizationItems } = useDataStore();
  let item = organizationItems.find(
    (x) => x.id == idOrCode || x.pathCode == idOrCode
  );
  return item?.name || "";
};

const getRegionName = (idOrCode: string) => {
  const { regionItems } = useDataStore();
  let item = regionItems.find((x) => x.id == idOrCode);
  return item?.name || "";
};

const getEnterpriseName = (idOrCode: string) => {
  const { enterpriseItems } = useDataStore();
  let item = enterpriseItems.find(
    (x) => x.id == idOrCode || x.enCode == idOrCode
  );
  return item?.name || "";
};

export {
  getUserName,
  getUserNames,
  getOrganizeName,
  getEnterpriseName,
  getRegionName,
};
